package main.Trees;

import main.Link.SQLLink;
import main.SQL.objects.SQLDocument;

import javax.swing.tree.DefaultMutableTreeNode;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class SmetNode extends DefaultMutableTreeNode
{
    private String name, code, num, unit, smNum, ready;
    private BigDecimal volume, cost, hr, mr, factor, factorFull;
    public Boolean isString, isHeader, isImportFactage = false;
    private int id, parentId, smrCount;
    public String type, high;
    private SQLDocument document;
    private SmetNode smet;

    private ArrayList<SQLLink> links = new ArrayList<>();

    //OpenSmetStructure constructors
    public SmetNode( int parentId, int id, String name ) {

        this.name = name;
        this.id = id;
        this.parentId = parentId;
        this.isString = false;
        this.isHeader = false;
        this.high = "";
        this.ready = "";

    }

    //root node
    public SmetNode( String name ) {
        this.name = name;
        this.isString = false;
        this.isHeader = false;
        this.high = "";
        this.ready = "";
    }

    //sms node
    public SmetNode( String name, int id, String num, Boolean isHeader ) {
        this.name = name;
        this.id = id;
        this.num = num;
        this.isString = false;
        this.isHeader = isHeader;
        this.high = "";
        this.ready = "";
    }

    public SmetNode( String num, int id, String name, String unit, Double volume, Double cost, Double hr, Double mr, Boolean isString, int parentId, String smNum ) {
        this.num = num;
        this.id = id;
        this.name = name;
        this.unit = unit;
        this.volume = new BigDecimal(volume).setScale(6, RoundingMode.HALF_UP);
        this.cost = new BigDecimal(cost).setScale(6, RoundingMode.HALF_UP);
        this.hr = new BigDecimal(hr).setScale(6, RoundingMode.HALF_UP);
        this.mr = new BigDecimal(mr).setScale(6, RoundingMode.HALF_UP);
        this.factor = new BigDecimal(0).setScale(6, RoundingMode.HALF_UP);
        this.factorFull= new BigDecimal(1).setScale(6, RoundingMode.HALF_UP);
        this.isString = isString;
        this.parentId = parentId;
        this.isHeader = false;
        this.smNum = smNum;
        this.high = "";
        this.ready = "";
    }

    public SmetNode(SmetNode smet) {
        this.num = smet.getNum();
        this.id = smet.id;
        this.name = smet.name;
        this.unit = smet.unit;
        this.volume = smet.volume;
        this.cost = smet.cost;
        this.hr = smet.getHR();
        this.mr = smet.getMR();
        this.factor= smet.getFactor();
        this.factorFull= smet.getFactorFull();
        this.isString = smet.isString;
        this.parentId = smet.parentId;
        this.isHeader = false;
        this.smNum = smet.smNum;
        this.high = "";
        this.ready = "";
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() { return name; }

    public void setName( String name ) { this.name = name; }

    public String getCode() { return code; }

    public void setCode( String description )	{	this.code = description; }

    public void setHigh(String flag) {
        this.high = flag;
    }

    public String getHigh() {
        return high;
    }

    public void setReady(String ready) {this.ready = ready;}

    public String getReady() {
        return ready;
    }

    public List<SmetNode> getChildren() {return children; }

    public void setAllowChildren ( Boolean val ) { super.allowsChildren = val; }

    public String toString() { return name; }

    public String getNum() { return num;	}

    public String getUnit() {	return unit; }

    public void setUnit(String unit) {	this.unit = unit; }

    public BigDecimal getVolume() {	return volume; }

    public void setVolume(BigDecimal volume) {this.volume = volume;}

    public BigDecimal getCost() {	return cost; }

    public BigDecimal getHR() {	return hr; }

    public BigDecimal getMR() {	return mr; }

    public BigDecimal getFactor() { return factor; }

    public void setFactor(BigDecimal factor) { this.factor = factor; }

    public int getId() { return id; }

    public int getParentId() { return parentId; }

    public void setParentId(int parentId) { this.parentId = parentId; }

    public BigDecimal getFactorFull() { return factorFull; }

    public void setFactorFull(BigDecimal factorFull) { this.factorFull = factorFull; }

    public String getSmNum() {
        return smNum;
    }

    public void setSmNum(String smNum) {
        this.smNum = smNum;
    }

    public void setSmrCount(int smrCount) {
        this.smrCount = smrCount;
    }

    public int getSmrCount() {
        return smrCount;
    }

    public Boolean getIsImportFactage() {
        return isImportFactage;
    }

    public void setIsImportFactage(Boolean isImportFactage) {
        this.isImportFactage = isImportFactage;
    }

    public void setSmetHighlight() {
        if (factor.compareTo(factorFull) == 0) {
            ready = ("ready");
        } else if (factor.signum() == 1) {
            ready = "inProgress";
        } else {
            ready = "";
        }
    }

    public ArrayList<SQLLink> getLinks() {
        return links;
    }

    public SQLDocument getDocument() {
        return document;
    }

    public void setDocument(SQLDocument document) {
        this.document = document;
    }

    public SmetNode getSmet() {
        return smet;
    }

    public void setSmet(SmetNode smet) {
        this.smet = smet;
    }
}